<?php
// 1 PostScript point = 1/72 inches = 25.4/72 mm = 0.3527 mm)
//. 12 points to the pica
/*if (strstr($_SERVER['REQUEST_URI'],'nul.php')){
header('HTTP/1.0 404 Not Found');
echo "0000000000000";
 * }*/
//$out=array_map(function($x) {return $x*$x;}, range(0, 9))
//haskell: thread ring programs
//usr fills rows or columns of records
////every record is stored as a paep file
//calls met params naar random image op web voor logo + file structure
//globals: $CONTEXT,$TAG1,$NOIMG,$CRLF;
//include "babsym.php";

global $CRLF; $CRLF='<br />';
//function crlf($crlf='<br />'){ return $crlf; }
$TAG1=' />';
//$NOIMG=perr('No Image');
$CONTEXT=array();

//function pdoc($i){}
function pbr(){ echo'<br />'; 	}
function perr($s){ echo '<pre>',$s,'</pre>'; }
function berr($s){
    $err=array('<pre>',$s,'</pre>');
    $tag=implode('',$err); return $tag;
}
function pinclude($file, $type, $get = null) {
    $p = explode('/', $file);
    $file = end($p);
    $dir = '';
    $n = count($p) - 1;

    for ($i = 0; $i < $n; $i++)
        $dir .= $p[$i] . '/';

    if ($get !== null) {
        $tmp = $_GET; // back up
        $_GET = array();
        $get = explode('&', $get);
        $n = count($get);

        for ($i = 0; $i < $n; $i++) {
            if (strpos($get[$i], '=') === false)
                $_GET[$get[$i]] = 1;
            else {
                list($name, $val) = explode('=', $get[$i], 2);
                $_GET[$name] = $val;
            }
        }
    }

    ob_start();
    chdir($dir);
    require $file;
    $out = ob_get_clean();

    if ($tmp)
        $_GET = $tmp;

    return $out;
}

function pdivel(){
/*
readonly NodeList 	childNodes
children [IE]
String 	className
style 	currentStyle [IE]
String 	dir
HTMLDocument 	document
Array 	filters [IE]
          Valid only for some elements.
String 	id
String 	innerHTML [IE]
String 	innerText [IE]
          Valid for block elements only. Currently implemented as a readonly property.
String 	lang
number 	offsetHeight
number 	offsetLeft
number 	offsetParent
number 	offsetTop
number 	offsetWidth
style 	style
String 	title
String 	uniqueID [IE]
*/
}



/*function pstart($title='',$meta='',$css='',$js=''){
  $doctypes=array(
  '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
  '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
  );
  echo'<html xmlns="http://www.w3.org/1999/xhtml"><head>';
  if(is_array($css)){
    foreach ($css as &$sheet){ echo'\n @import url("',$sheet,'")'; }
  }else{
    echo'<style type="text/css" media="all">\n',$css,'</style>'; }
  if(is_array($js)){
    foreach ($js as &$script){ echo'<script type="text/javascript" src="',
      $script,'"></script>'; }
  }
//<link type="text/css" rel="StyleSheet" href="css/winclassic.css" />
  echo'<title>'.$title.'</title></head><body>';
  //	<link href="style-.css" rel="stylesheet" type="text/css" media="screen" />
}

function bstop($ps=''){ return'</body></html>'; }

function bscript($ps){
    $iframe=array('<script type="text/javascript">//<![CDATA[',$ps,'//]]></script>');
    $tag=implode('',$iframe);
    return $tag;
}

function btable($pa){
  $CRLF='<br />';
  $table=array('<table border=1>');
  foreach ($pa as $value) {
    if ($value==$CRLF){
	  if (count($table)==1){ $table=array('<table border=1><tr>'); }
	  else { $table[]='</tr><tr>';}
	}else{ $table[]='<td>'.$value.'</td>'; }}
	$table[]='</tr></table>';
    return $table;
}




function bnotempty($ps){ //return true if not empty
   if($ps<>''){ return true; } else { return false; }
}

function bform($contents,$script='form.php',$encoding=''){
	if (is_array($contents)){ $contents=implode('',$contents); }
	if ($encoding<>'') { $encoding=' enctype="' . $encoding . '" '; }
    $form=array('<form',$encoding ,'action="',$script,'" method="post">',$contents,'</form>');
    $tag=implode('',$form);
    return $tag;
}
function pform($contents,$script='form.php',$method='post',$encoding=''){
  if(is_array($contents)){ $contents=implode('',$contents); }
  if($encoding<>'') { $encoding=' enctype="' . $encoding . '" '; }
  echo'<form',$encoding ,(bnotempty($script)?' action="'.$script.'"':''),
  ' method="post">',$contents,'</form>';
}
function plabel($ps){ echo'<label>',$ps,'</label>'; }
function binput($name,$type,$value='',$label=''){
  if ($label<>''){ $label='<label>' . $label . '</label>'; }
  $value='" value="' . $value;
  $input=array($label,'<input name="',$name,'" type="',$type,$value,'" />');
  return $input;
}
function pinput($type,$name,$value='',$label=''){
  if ($label<>''){ echo'<label>',$label,'</label>'; }
  echo$label,'<input name="',$name,'" type="',$type,'" value="',$value,'" />';
}

function jslib($libname){
  switch($libname){
    case'jquery':return'http://code.jquery.com/jquery.js'; break;
	case'jquerymin':return'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'; break;
	case'jclipboardmin':return'../js/jquery.clipboard.min.js'; break;
	case'jclipboard':return'../js/jquery.clipboard.js'; break;
	case'xx':return''; break;
    case'scapi':return'../js/soundcloud.player.api.js'; break;
    case'scplayer':return'../js/sc-player.js'; break;
	default: return'';
  }
}

function jslibs($libs){
  $c=count($libs);
  for($i=0; $i<$c; ++$i){
    $libs[$i]='<script type="text/javascript" src="'.jslib($libs[$i]).'"></script>';
  }
  return implode($libs);
//  echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}

function pselect($pa,$name='',$selected='',$class='',$id=''){//todo option classing with array params
  $options=array();
  foreach($pa as $option){
    if($option==$selected){ $options[]=boption($option,$option,true);
	}else{ $options[]=boption($option,$option); }
  }
  echo'<select',
    (bnotempty($name)?' name="'.$name.'"':''),
	(bnotempty($class)?' class="'.$class.'"':''),
	(bnotempty($id)?' id="'.$id.'"':''),
  '>',implode($options),'</select>';
}

function poption($ps,$value=''){
    if ($value<>'') { $value=' value="' . $value . '" '; }
    $option=array('<option ',$value,'>',$ps,'</label>');
    $tag=implode('',$option);
    return $tag;
}
function boption($ps,$value='',$selected=''){
    if ($value<>'') { $value=' value="' . $value . '" '; }
    $option=array('<option ',$value,(bnotempty($selected)?' selected="selected"':''),
	  '>',$ps,'</option>');
    $tag=implode('',$option);
    return $tag;
}

function htag($ps,$tag){ return '<'.$tag.'>'.$ps.'</'.$tag.'>'; }

function btag($data,$funk,$prefix='',$suffix=''){
  global $CRLF;
  $tags=array();
  foreach($data as $datum){
    if($datum==$CRLF){$tags[]=$datum;
    }else{
      $cmd=$prefix.$datum.$suffix;
	  $result=call_user_func($funk,$cmd);
	  if(is_array($result)){ $tags[]=implode($result);
	  }else{ $tags[]=$result; }
	}
  }
  return $tags;
}



*/
function pdir($path='.'){
  if($handle=opendir($path)){
    while(false!==($file=readdir($handle))){ if(substr($file,0,1)!=".")echo "$file\n"; }
  }closedir($handle); }

function bdir($path='.',$cols=0){
    //extend to class with mehods for output
  if($handle=opendir($path)){
    $files=array(); $count=0;
    while(false!==($file=readdir($handle))){
      if(substr($file,0,1)!="."){ $files[]=$file; }
      if($cols>0 and $count==$cols+1){ $count=1; $files[]='<br />'; }
      ++$count;
    }
    closedir($handle);
    return $files;
  }
}
/*
function bdir2($path='./'){
if($handle=opendir($path)){
  $dirs=array(); $files=array();
  $count=0; $cols=0;
  while(false!==($file=readdir($handle))){
    if(substr($file,0,1)=="."){  }
    else if(is_dir($path.$file)){ $dirs[]=$file; }
    else{ $files[]=$file; ++$count; }
  }
  closedir($handle);
  echo implode('<br />',$files);
}*/

/*function ls($path,$dirs=true,$paths=false){
//$path='./plugin/';
if($handle=@opendir($path)){
  $path=($paths)?$path:'';
  $dirs=array(); $files=array();
  $count=0; $cols=0;
  while(false!==($file=readdir($handle))){
    if(substr($file,0,1)=="."){  }
    else if(is_dir($path.$file)){
      if($dirs){ $dirs[]=$file; }
      else{ $files[]=$path.$file; }
    }
    else{
      $files[]=$file;
      ++$count;
    }
  }
  closedir($handle);
  echo implode('<br />',$files);
}
}*/



?>
